package com.zwan.oam_rtc.service;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.zwan.oam_rtc.bean.appdemoentity.AcmeRtcParticipantsVo;
import com.zwan.oam_rtc.bean.appdemoentity.SysUser;
import com.zwan.oam_rtc.bean.appdemoentity.ZWUserListEntity;
import com.zwan.oam_rtc.constants.appconstants.Constants;
import com.zwan.oam_rtc.utils.apputils.ServletUtils;
import com.zwan.oam_rtc.utils.apputils.StringUtils;
import com.zwan.oam_rtc.utils.messages.StringUtil;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class AppService {

    /**
     * 获取request
     */
    public HttpServletRequest getRequest() {
        return ServletUtils.getRequest();
    }

    /**
     * 获取response
     */
    public HttpServletResponse getResponse() {
        return ServletUtils.getResponse();
    }

    public Integer getCurrentUserId() {
        String currentId = getRequest().getHeader(Constants.CURRENT_ID);
        if (StringUtils.isNotBlank(currentId)) {
            return Integer.valueOf(currentId);
        }
        return 0;
    }

    public List<AcmeRtcParticipantsVo> convertAcmeRtcParticipantsVoList(List<ZWUserListEntity> userListEntities) {
        List<AcmeRtcParticipantsVo> participants = new ArrayList<>();
        if (userListEntities!=null && userListEntities.size() > 0) {
            for (int i = 0; i < userListEntities.size(); i++) {
                ZWUserListEntity userEntity = userListEntities.get(i);
                AcmeRtcParticipantsVo acmeRtcParticipantsVo = new AcmeRtcParticipantsVo();

                String display = userEntity.getRealName();
                String userName = display;
                String platform = "1";

                acmeRtcParticipantsVo.setUserName(userName);
                acmeRtcParticipantsVo.setPlatform(platform);
                acmeRtcParticipantsVo.setDisplay(display);
                acmeRtcParticipantsVo.setPosition(userEntity.getPosition());
                acmeRtcParticipantsVo.setTrueName(userName);
                participants.add(acmeRtcParticipantsVo);                
            }
        }
        return participants;
    }
}
